﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace Aga.GestionDeArchivos.Common
{
    public class PagedList<T> : IEnumerable<T>
    {
        public PagedList()
        {
            Items = new List<T>();
        }

        public PagedList(IEnumerable<T> items, int pageIndex, int pageCount, int pageSize, int totalCount)
        {
            ItemsCount = totalCount;
            Items = items.Take(pageSize);
            PageIndex = pageIndex;
            PageSize = pageSize;
            PageCount = pageCount;
        }

        public IEnumerable<T> Items { get; private set; }
        public int ItemsCount { get; set; }
        public int PageCount { get; set; }
        public int PageSize { get; set; }
        public int PageIndex { get; set; }

        public int Count
        {
            get
            {
                return Items != null ? Items.Count() : 0;
            }
        }

        public bool IsFirstPage
        {
            get
            {
                return PageIndex == 0;
            }
        }
        public bool IsLastPage
        {
            get
            {
                return PageIndex == PageCount - 1;
            }
        }
        public int PageNumber
        {
            get
            {
                return PageIndex + 1;
            }
        }

        #region IEnumerable<T> Members

        public IEnumerator<T> GetEnumerator()
        {
            return this.Items.GetEnumerator();
        }

        #endregion

        #region IEnumerable Members

        IEnumerator IEnumerable.GetEnumerator()
        {
            return this.Items.GetEnumerator();
        }

        #endregion
    }
}
